package cc.mrbird.febs.buss.service.impl;

import cc.mrbird.febs.common.entity.FebsConstant;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.buss.entity.MenuTitle;
import cc.mrbird.febs.buss.mapper.MenuTitleMapper;
import cc.mrbird.febs.buss.service.IMenuTitleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.beans.factory.annotation.Autowired;
import cc.mrbird.febs.common.utils.SortUtil;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.*;
/**
 *  Service实现
 *
 * @author Lujingyuan
 * @date 2021-10-13 20:49:53
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class MenuTitleServiceImpl extends ServiceImpl<MenuTitleMapper, MenuTitle> implements IMenuTitleService {

    @Autowired
    private MenuTitleMapper menuTitleMapper;


    @Override
    public IPage<MenuTitle> findMenuTitleDetail(QueryRequest request, HashMap<String,String> map) {
        Page<MenuTitle> page = new Page<MenuTitle>(request.getPageNum(), request.getPageSize());
        SortUtil.handlePageSort(request, page, "id", FebsConstant.ORDER_ASC, false);
        return this.baseMapper.findMenuTitleDetailPageByMap(page,map);
    }

    @Override
    public List<MenuTitle> findMenuTitles(MenuTitle menuTitle) {
	    LambdaQueryWrapper<MenuTitle> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional
    public void add (MenuTitle menuTitle) {
        menuTitle.setId(UUID.randomUUID().toString().replace("-", "").toLowerCase());
        menuTitleMapper.insertOne(menuTitle);
    }

    @Override
    @Transactional
    public void updateMenuTitle(MenuTitle menuTitle) {
        this.saveOrUpdate(menuTitle);
    }

    @Override
    @Transactional
    public void deleteMenuTitle(MenuTitle menuTitle) {
        LambdaQueryWrapper<MenuTitle> wrapper = new LambdaQueryWrapper<>();
	    // TODO 设置删除条件
	    this.remove(wrapper);
	}

    @Override
    @Transactional
    public void deleteMenuTitle(String[] ids) {
        List<String> list = Arrays.asList(ids);
        // 删除用户
        this.removeByIds(list);
    }

    @Override
    public List<MenuTitle> selectByMap(Map<String,Object> map){
        return menuTitleMapper.selectByMap(map);
    }
}
